package com.fone.player.online.adapter;

import java.util.ArrayList;
import java.util.Random;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AbsListView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.fone.player.R;
import com.fone.player.client.HotspotRst.Cnt;
import com.fone.player.client.HotspotRst.Module;
import com.fone.player.client.Request;
import com.fone.player.entity.RedirectInfo;
import com.fone.player.online.activity.SubjectActivity;
import com.fone.player.play.PlayerFrom;
import com.fone.player.util.Activity2poster;
import com.fone.player.util.FoneUtil;
import com.fone.player.util.L;
import com.fone.player.util.ScreenUtil;
import com.fone.player.view.MovieStarsView;
import com.fone.player.view.PostersView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

@DelegateAdaptersAnnotation(delegateAdapters = {
	HotAdapter.ViewOneDelegateAdapter.class,
	HotAdapter.ViewTwoDelegateAdapter.class,
	HotAdapter.ViewThreeDelegateAdapter.class,
	HotAdapter.ViewFourDelegateAdapter.class,
	HotAdapter.ViewFiveDelegateAdapter.class,
	HotAdapter.ViewSixDelegateAdapter.class,
	HotAdapter.ViewSevenDelegateAdapter.class,
})

public class HotAdapter extends DispatcherAdapter {

	/** 日志标签 */
//	private static final String TAG = "HotAdapter";

	private ArrayList<Module> moduleList;
	private static String host;
	private static String shost;
	static DisplayImageOptions options1;
	static DisplayImageOptions options2;
	private static final String TAG = "HotAdapter";

	public HotAdapter(Context context, String host,String shost, ArrayList<Module> moduleList) {
		super(context);
		this.host = host;
		this.shost = shost;
		this.moduleList = moduleList;
	}
	
	public void setData(String host,String shost,ArrayList<Module> moduleList){
		this.host = host;
		this.shost = shost;
		this.moduleList = moduleList;
		notifyDataSetChanged();
	}
	
	@Override
	public int getCount() {
		return moduleList.size();
	}

	@Override
	public Object getItem(int position) {
		
		return moduleList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public int getItemViewType(int position) {
		
		Module module = moduleList.get(position);
		int type =  Integer.valueOf(module.type.trim()) - 1;
		Log.i("HotAdapter", "getItemViewType position: " + position + " type: " + type );
		return type;
	}
	
	public static class BaseDelegateAdapter implements DelegateAdapter {
		
		@Override
		public View getView(int position, View convertView, ViewGroup parent,
				LayoutInflater inflater, Object item) {
			// TODO Auto-generated method stub
			return convertView;
		}
		
		/**
		 * 设置图片
		 */
		protected void setImageView(ImageView imageView, int defaultResourceId, String url, DisplayImageOptions options) {
			// 设置图片
			ImageLoader.getInstance().displayImage(FoneUtil.getAbsoluteUrl("", Request.getInstance().getSHost(), url), imageView, options);
		}
		
		/**
		 * 设置图片
		 */
		protected void setImageView(ImageView imageView, int defaultResourceId, String url) {
			// 设置图片
			ImageLoader.getInstance().displayImage(FoneUtil.getAbsoluteUrl("", Request.getInstance().getSHost(), url), imageView);
		}
		
		public RedirectInfo getRedirectInfo(Cnt cnt) {
			RedirectInfo redirectInfo = new RedirectInfo();
			redirectInfo.host = host;
			redirectInfo.utp = cnt.utp;
			redirectInfo.weibourl = cnt.weibourl;
			redirectInfo.url = cnt.url;
			redirectInfo.vgurl = cnt.url;
			redirectInfo.xyzplayurl = cnt.url;
			redirectInfo.dnfs = cnt.dfnt;
			redirectInfo.name = cnt.name;
			redirectInfo.ourl = cnt.ourl;
			redirectInfo.btnply = cnt.btnply;
			redirectInfo.pic = cnt.pic2;
			return redirectInfo;
		}
		
		protected class OnClicker implements OnClickListener {
			Cnt cnt;
			Context mContext;

			public OnClicker(Cnt cnt, Context context) {
				super();
				mContext = context;
				if (cnt != null) {
					this.cnt = cnt;
				}
			}

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				// 判断网络状态
				if (FoneUtil.isNetOkWithToast(mContext)) {
					Activity2poster.startActivity(mContext, getRedirectInfo(cnt));
				}
			}
		}
		
		/**
		 * 推荐维度 0 无纬度 1 时长 2 评分 3 更新至 4 自定义文字 5 自定义图片
		 */
		protected void getRmd(String rmd, String rmdval, TextView textView, MovieStarsView ratingView, ImageView imageView) {
			if(TextUtils.isEmpty(rmd) && TextUtils.isEmpty(rmdval)){
				textView.setVisibility(View.INVISIBLE);
				imageView.setVisibility(View.INVISIBLE);
				ratingView.setVisibility(View.INVISIBLE);
			}else if (rmd.equals("1")) {
				textView.setVisibility(View.VISIBLE);
				imageView.setVisibility(View.INVISIBLE);
				ratingView.setVisibility(View.INVISIBLE);
				textView.setText("播放时长"+rmdval.substring(0, 5));
			} else if (rmd.equals("2")) {
				textView.setVisibility(View.INVISIBLE);
				imageView.setVisibility(View.INVISIBLE);
				ratingView.setVisibility(View.VISIBLE);
				ratingView.rating(Integer.valueOf(rmdval));
				//textView.setText(rmdval + "分");
			} else if (rmd.equals("3")) {
				textView.setVisibility(View.VISIBLE);
				imageView.setVisibility(View.INVISIBLE);
				ratingView.setVisibility(View.INVISIBLE);
				textView.setText(rmdval);
			} else if (rmd.equals("4")) {
				textView.setVisibility(View.VISIBLE);
				imageView.setVisibility(View.INVISIBLE);
				ratingView.setVisibility(View.INVISIBLE);
				textView.setText(rmdval);
			} else if (rmd.equals("5")) {
				textView.setVisibility(View.INVISIBLE);
				imageView.setVisibility(View.VISIBLE);
				ratingView.setVisibility(View.INVISIBLE);
				setImageView(imageView, R.drawable.default_image_bg, rmdval);
				imageView.setVisibility(View.VISIBLE);
			} else if(rmd.equals("0")){//无推荐纬度
				textView.setVisibility(View.INVISIBLE);
				imageView.setVisibility(View.INVISIBLE);
				ratingView.setVisibility(View.INVISIBLE);
			}
		}

		/**
		 * 显示当前影片类型
		 * 
		 * 当影片为收费视频时，显示VIP 否则显示对应类型
		 * 
		 * ftv 当前视频是否收费 0 否 1 是 favtyp 收藏类型，内容类型(0 全部 1 电影 2 电视剧 3 动漫 4 综艺 5 原创 6
		 * 视频直播 7 音频直播 8 新闻 9 短片)
		 */
		protected void setType(String ftv, String favtyp, TextView textview) {

			if (TextUtils.isEmpty(ftv) || TextUtils.isEmpty(favtyp)) {
			} else if (ftv.equals("1")) {
				textview.setVisibility(View.VISIBLE);
				textview.setText("VIP");
			}
		}
		
		/**
		 * 控件相应监听
		 */

		protected class MoreClicker implements OnClickListener {
			Context mContext; 
			String url;

			public MoreClicker(String url, Context context) {
				super();
				this.url = url;
				mContext = context;
			}

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				// 判断网络状态
				if (FoneUtil.isNetOkWithToast(mContext)) {
					Intent intent = new Intent(mContext, SubjectActivity.class);
					intent.putExtra("url", url);
					mContext.startActivity(intent);
				}
			}
		}
	}
	
	
	@DelegateAdapterType(itemType = 0) 
	public static class ViewOneDelegateAdapter extends BaseDelegateAdapter {
		
		static class ViewHolderOne {
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent,
				LayoutInflater inflater, Object item) {
			
			ViewHolderOne viewHolder;
			if (convertView == null) {
				convertView = new PostersView(inflater.getContext());
				convertView.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, ScreenUtil.dp2px(210)));
				viewHolder = new ViewHolderOne();
				convertView.setTag(viewHolder);
			} else {
				viewHolder = (ViewHolderOne) convertView.getTag();
			}
			
			Log.i("HotAdapter", "ViewOneDelegateAdapter getView: " + convertView.toString() );
			
			Module module = (Module) item;
			
			if(module.cnts != null && module.cnts.cntList != null && !module.cnts.cntList.isEmpty()){
				L.v(TAG, "HotAdapter host = " + host);
				((PostersView)convertView).initData(true, shost, host, module.cnts.cntList, PlayerFrom.MAIN_BANNER);
				convertView.setVisibility(View.VISIBLE);
				
			} else {
				convertView.setVisibility(View.INVISIBLE);
			}
			// TODO Auto-generated method stub
			return convertView;
		}
	 
	}
	
	@DelegateAdapterType(itemType = 1) 
	public static class ViewTwoDelegateAdapter extends BaseDelegateAdapter {
		/**
		 * 模板二的holder
		 * 
		 * @author kongxiaojun
		 * @since 2014-6-20
		 */
		public static class ViewHolderTwo {
			RelativeLayout layoutOne;
			ImageView picOne;
			TextView nameOne;
			TextView timeOne;

			RelativeLayout layoutTwo;
			ImageView picTwo;
			TextView nameTwo;
			TextView timeTwo;

			RelativeLayout layoutThree;
			ImageView picThree;
			TextView nameThree;
			TextView timeThree;

			RelativeLayout layoutFour;
			ImageView picFour;
			TextView nameFour;
			TextView timeFour;

			RelativeLayout layoutFive;
			ImageView picFive;
			TextView nameFive;
			TextView timeFive;

			RelativeLayout layoutSix;
			ImageView picSix;
			TextView nameSix;
			TextView timeSix;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent,
				LayoutInflater inflater, Object item) {
			// TODO Auto-generated method stub
			ViewHolderTwo viewHolder;
			options1 = new DisplayImageOptions.Builder()
			.showImageOnLoading(R.drawable.default_220_184)
			.showImageForEmptyUri(R.drawable.default_220_184)
			.showImageOnFail(R.drawable.default_220_184)
			.cacheInMemory(true)
			.cacheOnDisk(true)
			.considerExifParams(true)
			.build();
			
			if (convertView == null) {
				convertView = inflater.inflate(R.layout.item_hot_two, null);
				viewHolder = new ViewHolderTwo();
				
				viewHolder.layoutOne = (RelativeLayout) convertView.findViewById(R.two.layout_one);
				viewHolder.picOne = (ImageView) convertView.findViewById(R.two.pic_one);
				viewHolder.nameOne = (TextView) convertView.findViewById(R.two.name_one);
				viewHolder.timeOne = (TextView) convertView.findViewById(R.two.time_one);
				
				viewHolder.layoutTwo = (RelativeLayout) convertView.findViewById(R.two.layout_two);
				viewHolder.picTwo = (ImageView) convertView.findViewById(R.two.pic_two);
				viewHolder.nameTwo = (TextView) convertView.findViewById(R.two.name_two);
				viewHolder.timeTwo = (TextView) convertView.findViewById(R.two.time_two);
				
				viewHolder.layoutThree = (RelativeLayout) convertView.findViewById(R.two.layout_three);
				viewHolder.picThree = (ImageView) convertView.findViewById(R.two.pic_three);
				viewHolder.nameThree = (TextView) convertView.findViewById(R.two.name_three);
				viewHolder.timeThree = (TextView) convertView.findViewById(R.two.time_three);
				
				viewHolder.layoutFour = (RelativeLayout) convertView.findViewById(R.two.layout_four);
				viewHolder.picFour = (ImageView) convertView.findViewById(R.two.pic_four);
				viewHolder.nameFour = (TextView) convertView.findViewById(R.two.name_four);
				viewHolder.timeFour = (TextView) convertView.findViewById(R.two.time_four);
				
				viewHolder.layoutFive = (RelativeLayout) convertView.findViewById(R.two.layout_five);
				viewHolder.picFive = (ImageView) convertView.findViewById(R.two.pic_five);
				viewHolder.nameFive = (TextView) convertView.findViewById(R.two.name_five);
				viewHolder.timeFive = (TextView) convertView.findViewById(R.two.time_five);
				
				viewHolder.layoutSix = (RelativeLayout) convertView.findViewById(R.two.layout_six);
				viewHolder.picSix = (ImageView) convertView.findViewById(R.two.pic_six);
				viewHolder.nameSix = (TextView) convertView.findViewById(R.two.name_six);
				viewHolder.timeSix = (TextView) convertView.findViewById(R.two.time_six);
				
				convertView.setTag(viewHolder);
			} else {
				viewHolder = (ViewHolderTwo) convertView.getTag();
			}
			
			Log.i("HotAdapter", "View2DelegateAdapter getView: " + convertView.toString() );
			
			ArrayList<Cnt> cntList = (ArrayList<Cnt>) ((Module)item).cnts.cntList;
			
			RandomList(cntList);

			// 第一页
			if (cntList != null && cntList.size() > 0) {
				Cnt cnt = cntList.get(0);
				// 设置图片
				setImageView(viewHolder.picOne, R.drawable.default_image_bg, cnt.pic1, options1);
				viewHolder.nameOne.setText(cnt.name);
//				viewHolder.timeOne.setText(cnt.timelen.substring(0, 5));
				viewHolder.layoutOne.setOnClickListener(new OnClicker(cnt, inflater.getContext()));
			} else {
				setImageView(viewHolder.picOne, R.drawable.com_btn_orange, "", options1);
				viewHolder.nameOne.setText("");
				viewHolder.layoutOne.setOnClickListener(null);
			}

			// 第二页
			if (cntList != null && cntList.size() > 1) {
				Cnt cnt = cntList.get(1);
				// 设置图片
				setImageView(viewHolder.picTwo, R.drawable.default_image_bg, cnt.pic1, options1);
				viewHolder.nameTwo.setText(cnt.name);
				viewHolder.layoutTwo.setOnClickListener(new OnClicker(cnt, inflater.getContext()));
			} else {
				setImageView(viewHolder.picTwo, R.drawable.com_btn_orange, "", options1);
				viewHolder.nameTwo.setText("");
				viewHolder.layoutTwo.setOnClickListener(null);
//				viewHolder.timeTwo.setText("");
			}

			// 第三页
			if (cntList != null && cntList.size() > 2) {
				Cnt cnt = cntList.get(2);
				// 设置图片
				setImageView(viewHolder.picThree, R.drawable.default_image_bg, cnt.pic1, options1);
				viewHolder.nameThree.setText(cnt.name);
				viewHolder.layoutThree.setOnClickListener(new OnClicker(cnt, inflater.getContext()));
			} else {
				setImageView(viewHolder.picThree, R.drawable.com_btn_orange, "", options1);
				viewHolder.nameThree.setText("");
				viewHolder.layoutThree.setOnClickListener(null);
			}

			// 第四页
			if (cntList != null && cntList.size() > 3) {
				Cnt cnt = cntList.get(3);
				// 设置图片
				setImageView(viewHolder.picFour, R.drawable.default_image_bg, cnt.pic1, options1);
				viewHolder.nameFour.setText(cnt.name);
				viewHolder.layoutFour.setOnClickListener(new OnClicker(cnt, inflater.getContext()));
			} else {
				setImageView(viewHolder.picFour, R.drawable.com_btn_orange, "", options1);
				viewHolder.nameFour.setText("");
				viewHolder.layoutFour.setOnClickListener(null);
			}

			// 第五页
			if (cntList != null && cntList.size() > 4) {
				Cnt cnt = cntList.get(4);
				// 设置图片
				setImageView(viewHolder.picFive, R.drawable.default_image_bg, cnt.pic1, options1);
				viewHolder.nameFive.setText(cnt.name);
				viewHolder.layoutFive.setOnClickListener(new OnClicker(cnt, inflater.getContext()));
			} else {
				viewHolder.nameFive.setText("");
				setImageView(viewHolder.picFive, R.drawable.com_btn_orange, "", options1);
				viewHolder.layoutFive.setOnClickListener(null);
			}

			// 第六页
			if (cntList != null && cntList.size() > 5) {
				Cnt cnt = cntList.get(5);
				// 设置图片
				setImageView(viewHolder.picSix, R.drawable.default_image_bg, cnt.pic1, options1);
				viewHolder.nameSix.setText(cnt.name);
				viewHolder.layoutSix.setOnClickListener(new OnClicker(cnt, inflater.getContext()));
			} else {
				setImageView(viewHolder.picSix, R.drawable.com_btn_orange, "", options1);
				viewHolder.nameSix.setText("");
				viewHolder.layoutSix.setOnClickListener(null);
			}
			
			if (cntList == null || cntList.isEmpty())  {
				convertView.setVisibility(View.INVISIBLE);
			}

			return convertView;
		}
		
		private void RandomList(ArrayList<Cnt> sequence) {

			Random random = new Random();
			for (int i = 0; i < sequence.size(); i++) {
				int p = random.nextInt(sequence.size());
				Cnt tmp = sequence.get(i);
				sequence.set(i, sequence.get(p));
				sequence.set(p, tmp);
			}
			random = null;

		}
	}
	
	

	

	/**
	 * 模板三
	 */

	@DelegateAdapterType(itemType = 2) 
	public static class ViewThreeDelegateAdapter extends BaseDelegateAdapter {


		/**
		 * 模版3 holder
		 * 
		 * @author kongxiaojun
		 * @since 2014-6-20
		 */
		static class ViewHolderThree {
			TextView name;
			TextView more;
		}
		
		@Override
		public View getView(int position, View convertView, ViewGroup parent,
				final LayoutInflater inflater, Object item) {
			final ViewHolderThree holder;
			if (convertView == null) {
				convertView = inflater.inflate(R.layout.item_hot_three, null);
				convertView.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, ScreenUtil.dp2px(27)));
				holder = new ViewHolderThree();
				holder.name = (TextView) convertView.findViewById(R.three.name);
				holder.more = (TextView) convertView.findViewById(R.three.more);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolderThree)convertView.getTag();
			}
			
			Log.i("HotAdapter", "View3DelegateAdapter getView: " + convertView.toString() );
			
			final Module module = (Module)item;

			if (TextUtils.isEmpty(module.url)) {
				holder.more.setVisibility(View.INVISIBLE);
			} else {
				holder.more.setVisibility(View.VISIBLE);
				holder.more.setOnClickListener(new View.OnClickListener() {
					
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						if (FoneUtil.isNetOkWithToast(inflater.getContext())) {
							Intent intent = new Intent(inflater.getContext(), SubjectActivity.class);
							intent.putExtra("url", module.url);
							inflater.getContext().startActivity(intent);
						}	
					}
				});
			}
			holder.name.setText(module.name);
			
			return convertView;
		}
		
		
	
	}
	
	/**
	 * 模板四
	 */

	@DelegateAdapterType(itemType = 3)
	public static class ViewFourDelegateAdapter extends BaseDelegateAdapter {

		/**
		 * 模版4 holder
		 * 
		 * @author kongxiaojun
		 * @since 2014-6-20
		 */
		static class ViewHolderFour {
			public TextView name;
			public TextView rmTxt;
			public ImageView type;
			public ImageView pic;
			public ImageView rmPic;
			public MovieStarsView rating;
		}
		
		@Override 
		public View getView(int position, View convertView, ViewGroup parent,
				LayoutInflater inflater, Object item) {
			
			ViewHolderFour viewHolder;
			options1 = new DisplayImageOptions.Builder()
			.showImageOnLoading(R.drawable.default_720_340)
			.showImageForEmptyUri(R.drawable.default_720_340)
			.showImageOnFail(R.drawable.default_720_340)
			.cacheInMemory(true)
			.cacheOnDisk(true)
			.considerExifParams(true)
			.build();
			
			if (convertView == null) {
				convertView = inflater.inflate(R.layout.item_hot_four, null);
				viewHolder = new ViewHolderFour();
				
				viewHolder.name = (TextView) convertView.findViewById(R.four.name);
				viewHolder.rmTxt = (TextView) convertView.findViewById(R.four.from);
				viewHolder.type = (ImageView) convertView.findViewById(R.four.type);
				viewHolder.pic = (ImageView) convertView.findViewById(R.four.pic);
				viewHolder.rmPic = (ImageView) convertView.findViewById(R.four.from_pic);
				viewHolder.rating = (MovieStarsView) convertView.findViewById(R.four.rating);
				convertView.setTag(viewHolder);
			
			} else {
				viewHolder = (ViewHolderFour) convertView.getTag();
			}
			
			Log.i("HotAdapter", "View4DelegateAdapter getView: " + convertView.toString() );
			
			ArrayList<Cnt> cntList = (ArrayList<Cnt>) ((Module)item).cnts.cntList;
			
			if (cntList != null && !cntList.isEmpty()) {
				Cnt cnt = cntList.get(0);
				// 设置图片
				setImageView(viewHolder.pic, R.drawable.default_image_bg, cnt.pic2, options1);
				viewHolder.name.setText(cnt.name);
				if (cnt.ftv.equals("1")) {
					viewHolder.type.setVisibility(View.VISIBLE);
				}else{
					viewHolder.type.setVisibility(View.INVISIBLE);
				}
				
				getRmd(cnt.rmd, cnt.rmdval, viewHolder.rmTxt, viewHolder.rating,viewHolder.rmPic);
				viewHolder.pic.setOnClickListener(new OnClicker(cnt, inflater.getContext()));
			} else {
				setImageView(viewHolder.pic, R.drawable.com_btn_orange, "", options1);
				viewHolder.name.setText("");
				viewHolder.type.setVisibility(View.INVISIBLE);
				getRmd("", "", viewHolder.rmTxt, viewHolder.rating, viewHolder.rmPic);
				viewHolder.pic.setOnClickListener(null);
			}
			
			return convertView;
		}
	}

	/**
	 * 模板五
	 */

	@DelegateAdapterType(itemType = 4)
	public static class ViewFiveDelegateAdapter extends BaseDelegateAdapter {

		/**
		 * 模版5 viewholder
		 * 
		 * @author kongxiaojun
		 * @since 2014-6-20
		 */
		static class ViewHolderFive {
			RelativeLayout layoutOne;
			TextView nameOne;
			TextView rmTxtOne;
			ImageView typeOne;
			ImageView picOne;
			ImageView rmPicOne;
			MovieStarsView ratingOne;

			RelativeLayout layoutTwo;
			TextView nameTwo;
			TextView rmTxtTwo;
			ImageView typeTwo;
			ImageView picTwo;
			ImageView rmPicTwo;
			MovieStarsView ratingTwo;
		}
		
		@Override
		public View getView(int position, View convertView, ViewGroup parent,
				LayoutInflater inflater, Object item) {
			
			ViewHolderFive viewHolder;
			options1 = new DisplayImageOptions.Builder()
			.showImageOnLoading(R.drawable.default_340_192)
			.showImageForEmptyUri(R.drawable.default_340_192)
			.showImageOnFail(R.drawable.default_340_192)
			.cacheInMemory(true)
			.cacheOnDisk(true)
			.considerExifParams(true)
			.build();
			
			if (convertView == null) {
				convertView = inflater.inflate(R.layout.item_hot_five, null);
				viewHolder = new ViewHolderFive();
				
				viewHolder.layoutOne = (RelativeLayout) convertView.findViewById(R.five.layout_one);
				viewHolder.nameOne = (TextView) convertView.findViewById(R.five.name_one);
				viewHolder.rmTxtOne = (TextView) convertView.findViewById(R.five.from_one);
				viewHolder.typeOne = (ImageView) convertView.findViewById(R.five.type_one);
				viewHolder.picOne = (ImageView) convertView.findViewById(R.five.pic_one);
				viewHolder.rmPicOne = (ImageView) convertView.findViewById(R.five.from_one_pic);
				viewHolder.ratingOne = (MovieStarsView) convertView.findViewById(R.five.rating_one);
				
				viewHolder.layoutTwo = (RelativeLayout) convertView.findViewById(R.five.layout_two);
				viewHolder.nameTwo = (TextView) convertView.findViewById(R.five.name_two);
				viewHolder.rmTxtTwo = (TextView) convertView.findViewById(R.five.from_two);
				viewHolder.typeTwo = (ImageView) convertView.findViewById(R.five.type_two);
				viewHolder.picTwo = (ImageView) convertView.findViewById(R.five.pic_two);
				viewHolder.rmPicTwo = (ImageView) convertView.findViewById(R.five.from_two_pic);
				viewHolder.ratingTwo = (MovieStarsView) convertView.findViewById(R.five.rating_two);
				
				convertView.setTag(viewHolder);
			} else {
				viewHolder = (ViewHolderFive) convertView.getTag();
			}
			
			Log.i("HotAdapter", "View5DelegateAdapter getView: " + convertView.toString() );
			
			ArrayList<Cnt> cntList = (ArrayList<Cnt>) ((Module)item).cnts.cntList;

			// 第一页
			if (cntList != null && cntList.size() > 0) {
				Cnt cnt = cntList.get(0);
				// 设置图片
				setImageView(viewHolder.picOne, R.drawable.default_image_bg, cnt.pic2, options1);
				viewHolder.nameOne.setText(cnt.name);
				getRmd(cnt.rmd, cnt.rmdval, viewHolder.rmTxtOne, viewHolder.ratingOne, viewHolder.rmPicOne);
				
				if (cnt.ftv.equals("1")) {
					viewHolder.typeOne.setVisibility(View.VISIBLE);
				}else{
					viewHolder.typeOne.setVisibility(View.INVISIBLE);
				}
				
				viewHolder.layoutOne.setOnClickListener(new OnClicker(cnt, inflater.getContext()));
			} else {
				setImageView(viewHolder.picOne, R.drawable.com_btn_orange, "", options1);
				viewHolder.nameOne.setText("");
				viewHolder.typeOne.setVisibility(View.INVISIBLE);
				getRmd("", "", viewHolder.rmTxtOne, viewHolder.ratingOne, viewHolder.rmPicOne);
				viewHolder.layoutOne.setOnClickListener(null);
			}

			// 第二页
			if (cntList != null && cntList.size() > 1) {
				Cnt cnt = cntList.get(1);
				// 设置图片
				setImageView(viewHolder.picTwo, R.drawable.default_image_bg, cnt.pic2, options1);
				viewHolder.nameTwo.setText(cnt.name);
				getRmd(cnt.rmd, cnt.rmdval, viewHolder.rmTxtTwo, viewHolder.ratingTwo, viewHolder.rmPicTwo);
				if (cnt.ftv.equals("1")) {
					viewHolder.typeTwo.setVisibility(View.VISIBLE);
				}else{
					viewHolder.typeTwo.setVisibility(View.INVISIBLE);
				}
				
				viewHolder.layoutTwo.setOnClickListener(new OnClicker(cnt, inflater.getContext()));
				
			} else {
				setImageView(viewHolder.picTwo, R.drawable.com_btn_orange, "", options1);
				viewHolder.nameTwo.setText("");
				getRmd("", "", viewHolder.rmTxtTwo, viewHolder.ratingTwo, viewHolder.rmPicTwo);
				viewHolder.typeTwo.setVisibility(View.INVISIBLE);
				viewHolder.layoutTwo.setOnClickListener(null);
			}
			
			if (cntList == null || cntList.isEmpty())  {
				convertView.setVisibility(View.INVISIBLE);
			}

			return convertView;
		}
	}


	/**
	 * 模板六
	 */
	
	@DelegateAdapterType(itemType = 5)
	public static class ViewSixDelegateAdapter extends BaseDelegateAdapter {

		/**
		 * 模版6 viewholder
		 * 
		 * @author kongxiaojun
		 * @since 2014-6-20
		 */
		static class ViewHolderSix {
			ImageView from;
			TextView more;
			TextView nameOne;
			ImageView picOne;
			TextView nameTwo;
			ImageView picTwo;
			TextView nameThree;
			ImageView picThree;
		}
		
		@Override
		public View getView(int position, View convertView, ViewGroup parent,
				LayoutInflater inflater, Object item) {
			ViewHolderSix holderSix;
			options1 = new DisplayImageOptions.Builder()
			.showImageOnLoading(R.drawable.default_340_192)
			.showImageForEmptyUri(R.drawable.default_340_192)
			.showImageOnFail(R.drawable.default_340_192)
			.cacheInMemory(true)
			.cacheOnDisk(true)
			.considerExifParams(true)
			.build();
			
			if (convertView == null) {
				convertView = inflater.inflate(R.layout.item_hot_six, null);
				holderSix = new ViewHolderSix();
				holderSix.from = (ImageView) convertView.findViewById(R.six.pic_from);
				holderSix.more = (TextView) convertView.findViewById(R.six.txt_more);
				holderSix.nameOne = (TextView) convertView.findViewById(R.six.name_one);
				holderSix.nameTwo = (TextView) convertView.findViewById(R.six.name_two);
				holderSix.nameThree = (TextView) convertView.findViewById(R.six.name_three);
				
				holderSix.picOne = (ImageView) convertView.findViewById(R.six.pic_one);
				holderSix.picTwo = (ImageView) convertView.findViewById(R.six.pic_two);
				holderSix.picThree = (ImageView) convertView.findViewById(R.six.pic_three);
				
				convertView.setTag(holderSix);
			} else {
				holderSix = (ViewHolderSix) convertView.getTag();
			}
			
			Log.i("HotAdapter", "View6DelegateAdapter getView: " + convertView.toString() );
			
			Module module = (Module)item;

			if (TextUtils.isEmpty(module.url)) {
				holderSix.more.setVisibility(View.INVISIBLE);
			} else {
				Log.v("Debug", "holderSix " + holderSix);
				Log.v("Debug", "module " + module);
				Log.v("Debug", "inflater " + inflater);
				
				holderSix.more.setOnClickListener(new MoreClicker(module.url, inflater.getContext()));
			}
			
			// 设置来源图片
			setImageView(holderSix.from, R.drawable.default_image_bg, module.pic);

			ArrayList<Cnt> cntList = (ArrayList<Cnt>) module.cnts.cntList;

			// 第一页
			if (cntList != null && cntList.size() > 0) {
				Cnt cnt = cntList.get(0);
				// 设置图片
				setImageView(holderSix.picOne, R.drawable.default_image_bg, cnt.pic2, options1);
				holderSix.nameOne.setText(cnt.name);
				holderSix.picOne.setOnClickListener(new OnClicker(cnt, inflater.getContext()));
			} else {
				setImageView(holderSix.picOne, R.drawable.com_btn_orange, "", options1);
				holderSix.nameOne.setText("");
				holderSix.picOne.setOnClickListener(null);
			}

			// 第二页
			if (cntList != null && cntList.size() > 1) {
				Cnt cnt = cntList.get(1);
				// 设置图片
				setImageView(holderSix.picTwo, R.drawable.default_image_bg, cnt.pic2, options1);
				holderSix.nameTwo.setText(cnt.name);
				holderSix.picTwo.setOnClickListener(new OnClicker(cnt, inflater.getContext()));
			} else {
				setImageView(holderSix.picTwo, R.drawable.com_btn_orange, "", options1);
				holderSix.nameTwo.setText("");
				holderSix.nameTwo.setOnClickListener(null);
			}

			// 第三页
			if (cntList != null && cntList.size() > 2) {
				Cnt cnt = cntList.get(2);
				// 设置图片
				setImageView(holderSix.picThree, R.drawable.default_image_bg, cnt.pic2, options1);
				holderSix.nameThree.setText(cnt.name);

				holderSix.picThree.setOnClickListener(new OnClicker(cnt, inflater.getContext()));
			} else {
				setImageView(holderSix.picThree, R.drawable.com_btn_orange, "", options1);
				holderSix.nameThree.setText("");
				holderSix.picThree.setOnClickListener(null);
			}
			
			if (cntList == null || cntList.isEmpty())  {
				convertView.setVisibility(View.INVISIBLE);
			}

			return convertView;
		}
	}
	
	/**
	 * 模板七
	 */
	
	@DelegateAdapterType(itemType = 6)
	public static class ViewSevenDelegateAdapter extends BaseDelegateAdapter {

		static class ViewHolderSeven {
			TextView nameOne;
			ImageView typeOne;
			TextView fromOne;
			ImageView picOne;
			ImageView picfromOne;
			MovieStarsView ratingOne;
			
			TextView nameTwo;
			ImageView typeTwo;
			TextView fromTwo;
			ImageView picTwo;
			ImageView picfromTwo;
			MovieStarsView ratingTwo;
			
			TextView nameThree;
			ImageView typeThree;
			TextView fromThree;
			ImageView picThree;
			ImageView picfromThree;
			MovieStarsView ratingThree;
		}
		
		@Override
		public View getView(int position, View convertView, ViewGroup parent,
				LayoutInflater inflater, Object item) {
			ViewHolderSeven viewHolder;
			
			options1 = new DisplayImageOptions.Builder()
			.showImageOnLoading(R.drawable.default_340_192)
			.showImageForEmptyUri(R.drawable.default_340_192)
			.showImageOnFail(R.drawable.default_340_192)
			.cacheInMemory(true)
			.cacheOnDisk(true)
			.considerExifParams(true)
			.build();
			
			options2 = new DisplayImageOptions.Builder()
			.showImageOnLoading(R.drawable.default_342_456)
			.showImageForEmptyUri(R.drawable.default_342_456)
			.showImageOnFail(R.drawable.default_342_456)
			.cacheInMemory(true)
			.cacheOnDisk(true)
			.considerExifParams(true)
			.build();
			
			if (convertView == null) {
				convertView = inflater.inflate(R.layout.item_hot_seven, null);
				
				viewHolder = new ViewHolderSeven();
				
				viewHolder.nameOne = (TextView) convertView.findViewById(R.seven.name_one);
				viewHolder.typeOne = (ImageView) convertView.findViewById(R.seven.type_one);
				viewHolder.fromOne = (TextView) convertView.findViewById(R.seven.from_one);
				viewHolder.picOne = (ImageView) convertView.findViewById(R.seven.pic_one);
				viewHolder.picfromOne = (ImageView) convertView.findViewById(R.seven.from_one_pic);
				viewHolder.ratingOne = (MovieStarsView) convertView.findViewById(R.seven.rating_one);
				
				
				viewHolder.nameTwo = (TextView) convertView.findViewById(R.seven.name_two);
				viewHolder.typeTwo = (ImageView) convertView.findViewById(R.seven.type_two);
				viewHolder.fromTwo = (TextView) convertView.findViewById(R.seven.from_two);
				viewHolder.picTwo = (ImageView) convertView.findViewById(R.seven.pic_two);
				viewHolder.picfromTwo = (ImageView) convertView.findViewById(R.seven.from_two_pic);
				viewHolder.ratingTwo = (MovieStarsView) convertView.findViewById(R.seven.rating_two);
				
				viewHolder.nameThree = (TextView) convertView.findViewById(R.seven.name_three);
				viewHolder.typeThree = (ImageView) convertView.findViewById(R.seven.type_three);
				viewHolder.fromThree = (TextView) convertView.findViewById(R.seven.from_three);
				viewHolder.picThree = (ImageView) convertView.findViewById(R.seven.pic_three);
				viewHolder.picfromThree = (ImageView) convertView.findViewById(R.seven.from_three_pic);
				viewHolder.ratingThree = (MovieStarsView) convertView.findViewById(R.seven.rating_three);
				
				convertView.setTag(viewHolder);
			} else {
				viewHolder = (ViewHolderSeven) convertView.getTag();
			}
			
			ArrayList<Cnt> cntList = (ArrayList<Cnt>) ((Module)item).cnts.cntList;
			
			Log.i("HotAdapter", "View7DelegateAdapter getView: " + convertView.toString() );

			// 第一页

			if (cntList != null && cntList.size() > 0) {
				Cnt cnt = cntList.get(0);
				setImageView(viewHolder.picOne, R.drawable.default_image_bg, cnt.pic2, options2);
				viewHolder.nameOne.setText(cnt.name);
				getRmd(cnt.rmd, cnt.rmdval, viewHolder.fromOne, viewHolder.ratingOne, viewHolder.picfromOne);
				
				if (cnt.ftv.equals("1")) {
					viewHolder.typeOne.setVisibility(View.VISIBLE);
				}else{
					viewHolder.typeOne.setVisibility(View.INVISIBLE);
				}
				
				viewHolder.picOne.setOnClickListener(new OnClicker(cnt, inflater.getContext()));
			} else {
				setImageView(viewHolder.picOne, R.drawable.com_btn_orange, "", options2);
				viewHolder.nameOne.setText("");
				getRmd("", "", viewHolder.fromOne, viewHolder.ratingOne, viewHolder.picfromOne);
				viewHolder.typeOne.setVisibility(View.INVISIBLE);
				viewHolder.picOne.setOnClickListener(null);
			}

			// 第二页
			if (cntList != null && cntList.size() > 1) {
				Cnt cnt = cntList.get(1);
				setImageView(viewHolder.picTwo, R.drawable.default_image_bg, cnt.pic2, options1);
				viewHolder.nameTwo.setText(cnt.name);
				getRmd(cnt.rmd, cnt.rmdval, viewHolder.fromTwo, viewHolder.ratingTwo, viewHolder.picfromTwo);
//				holderSeven.typeTwo.setText(getType(cnt.ftv, cnt.favtyp));
				
				if (cnt.ftv.equals("1")) {
					viewHolder.typeTwo.setVisibility(View.VISIBLE);
				}else{
					viewHolder.typeTwo.setVisibility(View.INVISIBLE);
				}
					
//				setType(cnt.ftv, cnt.favtyp, viewHolder.typeTwo);

				viewHolder.picTwo.setOnClickListener(new OnClicker(cnt, inflater.getContext()));
			} else {
				setImageView(viewHolder.picTwo, R.drawable.com_btn_orange, "", options1);
				viewHolder.nameTwo.setText("");
				getRmd("", "", viewHolder.fromTwo,viewHolder.ratingTwo, viewHolder.picfromTwo);
				viewHolder.typeTwo.setVisibility(View.INVISIBLE);
				viewHolder.picTwo.setOnClickListener(null);
			}

			// 第三页
			if (cntList != null && cntList.size() > 2) {
				Cnt cnt = cntList.get(2);
				setImageView(viewHolder.picThree, R.drawable.default_image_bg, cnt.pic2, options1);
				viewHolder.nameThree.setText(cnt.name);
				getRmd(cnt.rmd, cnt.rmdval, viewHolder.fromThree, viewHolder.ratingThree, viewHolder.picfromThree);
//				holderSeven.typeThree.setText(getType(cnt.ftv, cnt.favtyp));
				
				if (cnt.ftv.equals("1")) {
					viewHolder.typeThree.setVisibility(View.VISIBLE);
				}else{
					viewHolder.typeThree.setVisibility(View.INVISIBLE);
				}
					
//				setType(cnt.ftv, cnt.favtyp, viewHolder.typeThree);
				viewHolder.picThree.setOnClickListener(new OnClicker(cnt, inflater.getContext()));
			} else {
				setImageView(viewHolder.picThree, R.drawable.com_btn_orange, "", options1);
				viewHolder.nameThree.setText("");
				getRmd("", "", viewHolder.fromThree, viewHolder.ratingThree, viewHolder.picfromThree);
				viewHolder.typeThree.setVisibility(View.INVISIBLE);
				viewHolder.picThree.setOnClickListener(null);
			}
			
			if (cntList == null || cntList.isEmpty())  {
				convertView.setVisibility(View.INVISIBLE);
			}

			return convertView;
			
		}
	}


}
